﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AplicacaoReserva.ContactosForms
{
    public partial class ListarContactosForm : Form
    {
        public int IDAgencia;

        public int idContacto;

        public ListarContactosForm()
        {
            InitializeComponent();
        }

        private void btnContRemover_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Tens a certeza?", "Remover Contacto", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    ContactoServiceReference.WCFContactoClient contactos = new ContactoServiceReference.WCFContactoClient();

                    contactos.delete(idContacto);

                    MessageBox.Show("Removido com sucesso!", "Remover Cliente", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Occoreu um erro:\n" + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        
        
        private void ListarContactosForm_Load(object sender, EventArgs e)
        {
            try
            {
                ContactoServiceReference.WCFContactoClient wcfContacto = new ContactoServiceReference.WCFContactoClient();
                
                dgv_ListaContactos.DataSource = wcfContacto.getByAgencia(IDAgencia);

                wcfContacto.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Occoreu um erro:\n" + ex.ToString(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnContOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dgv_ListaContactos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            idContacto = int.Parse(dgv_ListaContactos.Rows[e.RowIndex].Cells[0].Value.ToString());

            btnContRemover.Enabled = true;
        }
    }
}
